<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>设计简单计时器</title>
</head>
<body>
    <input type="text" name="count" id="inp" value="0" />
    <br />
    <input type="button" value="开始" onclick="start()">
    <input type="button" value="暂停" onclick="pause()">
    <input type="button" value="停止" onclick="stop()">
</body>
<script>
    let inp = document.getElementById("inp");
    let count = 0;

    function change(){
        count++;
        inp.value = count;
    }

    //定义接收定时器的返回值的变量
    let timer = null;

    //开始
    function start() {
        //设置定时器
        timer = setInterval(change,1000)
    }

    //暂停
    function pause() {
        //清除定时器
        clearInterval(timer)
    }

    //停止
    function stop() {
        //清除定时器
        clearInterval(timer)
        //归零操作
        count = 0;
        inp.value = count;
        timer = null;
    }

</script>
</html>